package com.ruoyi.knowledge.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.knowledge.articlecollect.domain.ArticleCollect;
import com.ruoyi.knowledge.articlecollect.service.IArticleCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 文章收藏管理Controller
 * 
 * @author Jm
 * @date 2025-08-12
 */
@RestController
@RequestMapping("/articlecollect/articlecollect")
public class ArticleCollectController extends BaseController
{
    @Autowired
    private IArticleCollectService articleCollectService;

    /**
     * 查询文章收藏管理列表
     */
    @PreAuthorize("@ss.hasPermi('articlecollect:articlecollect:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArticleCollect articleCollect)
    {
        startPage();
        List<ArticleCollect> list = articleCollectService.selectArticleCollectList(articleCollect);
        return getDataTable(list);
    }

    /**
     * 导出文章收藏管理列表
     */
    @PreAuthorize("@ss.hasPermi('articlecollect:articlecollect:export')")
    @Log(title = "文章收藏管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArticleCollect articleCollect)
    {
        List<ArticleCollect> list = articleCollectService.selectArticleCollectList(articleCollect);
        ExcelUtil<ArticleCollect> util = new ExcelUtil<ArticleCollect>(ArticleCollect.class);
        util.exportExcel(response, list, "文章收藏管理数据");
    }

    /**
     * 获取文章收藏管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('articlecollect:articlecollect:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(articleCollectService.selectArticleCollectById(id));
    }

    /**
     * 新增文章收藏管理
     */
    @PreAuthorize("@ss.hasPermi('articlecollect:articlecollect:add')")
    @Log(title = "文章收藏管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArticleCollect articleCollect)
    {
        return toAjax(articleCollectService.insertArticleCollect(articleCollect));
    }

    /**
     * 修改文章收藏管理
     */
    @PreAuthorize("@ss.hasPermi('articlecollect:articlecollect:edit')")
    @Log(title = "文章收藏管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArticleCollect articleCollect)
    {
        return toAjax(articleCollectService.updateArticleCollect(articleCollect));
    }

    /**
     * 删除文章收藏管理
     */
    @PreAuthorize("@ss.hasPermi('articlecollect:articlecollect:remove')")
    @Log(title = "文章收藏管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(articleCollectService.deleteArticleCollectByIds(ids));
    }
}